//
//  WillViewController.m
//  MaxMovie
//
//  Created by Maxdong on 14-12-24.
//  Copyright (c) 2014年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "WillViewController.h"
#import "WillCell.h"
#import "NetworkHandler.h"
#import "WillNRViewController.h"
#import "UIImageView+WebCache.h"
#import "WillNRModel.h"
#import "WillShow.h"

//刷新


@interface WillViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain)NSArray * dataArray;
@end

@implementation WillViewController

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
//    UIButton * leftb =[UIButton buttonWithType:UIButtonTypeSystem];
//    leftb.frame =CGRectMake(20, 20, 20, 20);
//    UIImage * img1 =[UIImage imageNamed:@"left.png"];
//    [leftb setBackgroundImage:img1 forState:UIControlStateNormal];
//    [leftb addTarget:self action:@selector(leftbAction:) forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:leftb];
//    
    
    
    NSString * str =[NSString stringWithFormat:@"http://api.m.mtime.cn/Cinema/MovieComing.api"];
    [NetworkHandler connectioonNetGETDataWithURLString:str completion:^(id result) {
        
        self.dataArray=(NSArray *)result;
        [self.MYtableView reloadData];
    }];
    
    UITableView * WilltableView=[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    WilltableView.dataSource =self;
    WilltableView.delegate =self;
    
    [WilltableView registerClass:[WillCell class] forCellReuseIdentifier:@"reuse"];
    [self.view addSubview:WilltableView];
    [WilltableView release];
    
    self.MYtableView =WilltableView;
    
    
}




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return self.dataArray.count;
    
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"reuse";
    WillCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    //    if (cell){
    //        cell = [[[WillCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str] autorelease];
    //    }
    
    //图片 －－ 异步加载
    
    [cell.picView setImageWithURL:[NSURL URLWithString:[[self.dataArray objectAtIndex:indexPath.row]objectForKey:@"image"]]];
    
    //标题
    [cell.titleLabel setText:[[self.dataArray objectAtIndex:indexPath.row] objectForKey:@"title"]];
    
    //人数
    [cell.peopleLabel setText:[NSString stringWithFormat:@"%@人想看",[[self.dataArray objectAtIndex:indexPath.row]objectForKey:@"wantedCount"]]];
    
    //类型
    [cell.typeLabel setText:[NSString stringWithFormat:@"⭐️%@",[[self.dataArray objectAtIndex:indexPath.row]objectForKey:@"type"]]];
    
    //导演
    [cell.DYLabel setText:[NSString stringWithFormat:@"导演：%@",[[self.dataArray objectAtIndex:indexPath.row]objectForKey:@"director"]]];
    
    
    return cell;
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *strID = [[self.dataArray objectAtIndex:indexPath.row] valueForKey:@"id"];
    
    
    WillNRViewController *willNRvc = [[WillNRViewController alloc]init];
    NSString *str = [NSString stringWithFormat:@"http://api.m.mtime.cn/Showtime/MovieDetail.api?movieId=%@",strID];
    willNRvc.myUrl = str;
    [self.navigationController pushViewController:willNRvc animated:YES];
    
    
}

//左button
- (void)leftbAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}


@end
